package easy

func CommonChars(words []string) []string {
	temp := make([]int, 26)
	for i := range temp {
		temp[i] = int(^uint(0) >> 1)
	}
	for _, word := range words {
		freq := make([]int, 26)
		length := len(word)
		for i := 0; i < length; i++ {
			ch := word[i]
			freq[ch-'a']++
		}
		for i := 0; i < 26; i++ {
			temp[i] = min(temp[i], freq[i])
		}
	}
	ans := make([]string, 0)
	for i := 0; i < 26; i++ {
		for j := 0; j < temp[i]; j++ {
			ans = append(ans, string('a'+i))
		}
	}
	return ans
}
